import javax.swing.*;
import java.awt.*;

public class MainFrame extends JFrame {
    public MainFrame() {
        setTitle("物资库存管理系统");
        setSize(800, 600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        // 菜单栏
        JMenuBar menuBar = new JMenuBar();

        // 系统管理菜单
        JMenu systemMenu = new JMenu("系统管理");
        JMenuItem userManageItem = new JMenuItem("用户管理");
        JMenuItem exitItem = new JMenuItem("退出");
        systemMenu.add(userManageItem);
        systemMenu.addSeparator();
        systemMenu.add(exitItem);

        // 基础数据菜单
        JMenu baseDataMenu = new JMenu("基础数据");
        JMenuItem goodsItem = new JMenuItem("货物管理");
        JMenuItem buyerItem = new JMenuItem("采购员管理");
        JMenuItem supplierItem = new JMenuItem("供应商管理");
        JMenuItem salerItem = new JMenuItem("销售员管理");
        JMenuItem customerItem = new JMenuItem("客户管理");
        JMenuItem warehouseItem = new JMenuItem("仓位管理");
        baseDataMenu.add(goodsItem);
        baseDataMenu.add(buyerItem);
        baseDataMenu.add(supplierItem);
        baseDataMenu.add(salerItem);
        baseDataMenu.add(customerItem);
        baseDataMenu.add(warehouseItem);

        // 业务管理菜单
        JMenu businessMenu = new JMenu("业务管理");
        JMenuItem purchaseItem = new JMenuItem("采购管理");
        JMenuItem salesItem = new JMenuItem("销售管理");
        JMenuItem storageItem = new JMenuItem("库存管理");
        JMenuItem damageItem = new JMenuItem("报损管理");
        businessMenu.add(purchaseItem);
        businessMenu.add(salesItem);
        businessMenu.add(storageItem);
        businessMenu.add(damageItem);

        //视图
        JMenu functions = new JMenu("扩展功能");
        JMenuItem viewItem = new JMenuItem("视图查询");
        JMenuItem logsItem = new JMenuItem("操作日志");
        functions.add(viewItem);
        functions.add(logsItem);


        // 添加菜单到菜单栏
        menuBar.add(systemMenu);
        menuBar.add(baseDataMenu);
        menuBar.add(businessMenu);
        menuBar.add(functions);

        setJMenuBar(menuBar);

        // 添加事件监听
        userManageItem.addActionListener(e -> new UserManageFrame().setVisible(true));
        goodsItem.addActionListener(e -> new GoodsManageFrame().setVisible(true));
        buyerItem.addActionListener(e -> new BuyerManageFrame().setVisible(true));
        supplierItem.addActionListener(e -> new SupplierManageFrame().setVisible(true));
        salerItem.addActionListener(e -> new SalerManageFrame().setVisible(true));
        customerItem.addActionListener(e -> new CustomerManageFrame().setVisible(true));
        warehouseItem.addActionListener(e -> new WarehouseManageFrame().setVisible(true));
        purchaseItem.addActionListener(e -> new PurchaseManageFrame().setVisible(true));
        salesItem.addActionListener(e -> new SalesManageFrame().setVisible(true));
        storageItem.addActionListener(e -> new StorageManageFrame().setVisible(true));
        damageItem.addActionListener(e -> new DamageManageFrame().setVisible(true));
        viewItem.addActionListener(e -> new ViewQueryFrame().setVisible(true));
        logsItem.addActionListener(e -> new SimpleLogsManageFrame().setVisible(true));
        exitItem.addActionListener(e -> System.exit(0));

        // 状态栏
        JPanel statusPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        statusPanel.add(new JLabel("欢迎使用物资库存管理系统"));
        add(statusPanel, BorderLayout.SOUTH);
    }
}